/*
 * @Date: 2024-01-08 16:18:12
 * @LastEditors: lyx
 * @LastEditTime: 2024-01-23 14:32:38
 * @FilePath: \mt-middleware-server\config\nacos.ts
 * @Description:
 */
import { NacosConfigClient } from 'nacos';
import * as yaml from 'js-yaml';
// import { NacosConfigClient } from 'nacos-config';
// import { NacosNamingClient } from 'nacos-naming';
// const logger = console;

export class NacosManager {
  private client: NacosConfigClient;
  constructor() {
    console.log('getClient ok1');
    this.getClient();
    console.log('getClient ok2');
  }

  private async getClient() {
    this.client = new NacosConfigClient({
      username: process.env.nacos_username,
      password: process.env.nacos_password,
      serverAddr: process.env.nacos_serverAddr,
      namespace: process.env.nacos_namespace,
      requestTimeout: 6000,
    });
  }

  async getAllConfig() {
    const config = await this.client.getConfig(process.env.nacos_data_id, process.env.nacos_group);
    return yaml.load(config);
  }
}

